package com.acme.bankapp.domain.bank;

import com.acme.exceptions.NotEnoughFundsException;
import com.acme.exceptions.OverDraftLimitExceedException;


public class CheckingAccount extends AbstractAccount {

	private double overdraft;
	
	public CheckingAccount(double amount, double overdraft) {
		super(amount);
		this.overdraft = ((overdraft > 0) ? overdraft : 0);
	}
	
	@Override
	public void deposit(double amount) {
		if(amount >= 0) {
			this.balance += amount;
		} else {
			throw new IllegalArgumentException("amount should be non-negative!");
		}
	}
	
	@Override
	public void withdraw (double amount) throws NotEnoughFundsException {
		if (amount >= 0) {
			if (this.balance + this.overdraft >= amount) {
				this.balance -= amount;		
			} else {
				throw new OverDraftLimitExceedException("Not enough funds!",this);
			}
		} else{
			throw new IllegalArgumentException("amount should be non-negative!");
		}
		
	}

	@Override
	public double maximumAmountToWithdraw() {
		return (this.balance + this.overdraft);
	}

	@Override
	public String getAccountType(Account account) {
		return "CheckingAccount";
	}

}
